import libtcodpy as libtcod

# Object
class Object:
    def __init__(self, x, y, name, char, color, blocks, map):
        self.x = x
        self.y = y
        self.name = name
        self.char = char
        self.color = color
        self.blocks = blocks
        self.map = map
        
        map[x][y].objects.append(self)

    def move_to(self, x, y):
        self.map[self.x][self.y].objects.remove(self)
        self.x = x
        self.y = y
        self.map[x][y].objects.append(self)

    def move(self, dx, dy):
        if not self.map[self.x+dx][self.y+dy].is_blocked():
            self.move_to( self.x + dx, self.y + dy )

    def draw(self, con):
        libtcod.console_set_default_foreground(con, self.color)
        libtcod.console_put_char(con, self.x, self.y, self.char, libtcod.BKGND_NONE)

    def clear(self, con):
        libtcod.console_put_char(con, self.x, self.y, ' ', libtcod.BKGND_NONE)
